package Game;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;


public class Tower implements Entity{
	private int x;
	private int y;
	private static final int radie = 100;
	private Image graphic;
	private Circle c;

	private static final int DAMAGE = 1;
	private static final int ATTACK_SPEED = 200;
	private int timeSinceLastAttack;
	
	public Tower(int x, int y) throws SlickException{
		this.x = x*Map.TILESIZE;
		this.y = y*Map.TILESIZE;
		graphic = new Image("data/bird-tower.png");
		c = new Circle(this.x + Map.TILESIZE/2, this.y + Map.TILESIZE/2, radie);
		timeSinceLastAttack = ATTACK_SPEED;
	}
	
	public int getX() {return x;}
	public int getY() {return y;}

	
	
	/**
	 * Returns the graphic of the tower
	 * @return
	 */
	public Image getGraphic()
	{
		return graphic;
	}

	/**
	 * Returns a enemy that is in range of the tower
	 * @return a enemy that is in range of the tower
	 */
	public boolean isEnemyInRange(Enemy enemy)
	{
		return c.intersects(enemy.getTargetArea());
	}
	
	/**
	 * Tries to attack a given enemy. This depends on the attackspeed...
	 * @param enemy
	 * @param delta
	 */
	public void attack(Enemy enemy, int delta)
	{
		timeSinceLastAttack += delta;
		if (timeSinceLastAttack >= ATTACK_SPEED)
		{
			enemy.takeDamage(DAMAGE);
			timeSinceLastAttack = 0;
		}
	}

	public void draw() {
		graphic.draw(x, y);	
	}
	
	
	/**
	 * Draws a radius frame around the tower
	 */
	public void drawRadius(Graphics g) {
		g.draw(c);
	}

	/**
	 * Draws a transparent version of the tower
	 */
	public void drawTransparant() {
		graphic.draw(x, y, new Color (1, 1, 1, 0.5f));
		
	}
	/**
	 * Draws a red transparent version of the tower
	 */
	public void drawInvalid() {
		graphic.draw(x, y, new Color (255, 0, 0, 0.9f));		
	}
	

}